package com.block.mq;


import com.alibaba.fastjson.JSON;
import com.block.common.constant.MqConstant;
import com.block.common.exception.NotifyExceptionService;
import com.block.common.model.dto.SourceCountDTO;
import com.block.common.service.LogFactory;
import org.slf4j.Logger;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SourceCountInfoMqListener {

    private static final Logger log = LogFactory.getMqLog();

    @Autowired
    NotifyExceptionService notifyExceptionService;

    /**
     * 线索撞库统计等信息
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstant.Queue.SOURCE_COUNT_QUEUE),
            exchange = @Exchange(name = MqConstant.Exchange.ZHIKEYLAI_SOURCE),
            key = {MqConstant.KEY.SOURCE_COUNT_KEY}
    ))
    public void listenDirectQueue2(Message message){

        String messageBody = new String(message.getBody());
        log.info("【线索统计】【body】{}", new String(message.getBody()));
        try {

            SourceCountDTO sourceCountDTO = JSON.parseObject(messageBody, SourceCountDTO.class);
        }catch (Exception exception){
            exception.printStackTrace();
            notifyExceptionService.notifyNoticeInfo("MQ_RECEIVE_EXCE", "线索统计接收异常", messageBody, exception);
        }

    }

}
